function fval = qmd(w1, w2, C)

% quadratic form distance

% compute similaity matrix from cost matrix
A = 1-C/max(C(:));

wd = w1(:)*ones(1, numel(w2)) - ones(numel(w1), 1)*w2(:)';
wd2 = wd.^2;

fval = sqrt(sum(sum(wd2.*A)));
